
use.interval=0.0001
use.table=qnorm(seq(use.interval,1-use.interval,use.interval))
n.table.options=length(use.table)


simulate.SSP=function(N,params,v,maxCounter,stepSize,congruency,use.table,n.table.options) {
  
  rts=rep(0,N)
  resps=rep(0,N)
  
  times=cumsum(rep(stepSize,maxCounter))-stepSize
  
  standDevs=params["sd.start"]-(params["rate"]*times)
  standDevs[standDevs<0.001]=0.001
  
  a.top=1
  a.middle=pnorm(1.5,0,standDevs)
  a.bottom=pnorm(0.5,0,standDevs)
  
  # 注意，有maxCounter个v
  v = (2*params["p"]*congruency*(a.top-a.middle)) + 
    (2*params["p"]*congruency*(a.middle-a.bottom)) + 
    (params["p"]*(a.bottom-(1-a.bottom)))
  
  z=(params["z"]*(params["a"]+params["a"]))-params["a"]
  # browser()
  # maxcounter=150 stepsize=0.01times=[0.01,0.02...] s=params["stoch.s"]=0.1
  tmp=.C("DIFFtv",z=z,v=v,
         aU=params["a"],aL=-params["a"],ter=params["ter"],
         sv=params["sv"],sz=params["sz"],ster=params["ster"],
         s=params["stoch.s"],h=stepSize,resp=resps,rt=rts,
         n=N,maxiter=maxCounter,
         rangeLow=as.integer(0),rangeHigh=as.integer(n.table.options-1),
         randomTable=as.double(use.table)) 
  
  out=list(rt=tmp$rt,resp=tmp$resp)
}

